{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "40b83ec1-a9be-4bfe-9fd6-039b50d50c27",
   "metadata": {},
   "source": [
    "# Sphinx（文档生成工具）\n",
    "**翻译Gunicron帮助手册成中文版本**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fd8d686-8ae8-4264-8c0c-a15820a7053a",
   "metadata": {},
   "source": [
    "## 安装和配置\n",
    "\n",
    "### 安装sphinx、sphinx-intl和主题sphinx_rtd_theme\n",
    "\n",
    "```\n",
    "pip install sphinx sphinx-intl sphinx_rtd_theme\n",
    "```\n",
    "\n",
    "\n",
    "### 配置source/conf.py\n",
    "\n",
    "文件后追加以下内容：\n",
    "\n",
    "```\n",
    "language = 'en'\n",
    "locale_dirs = ['../locales/']\n",
    "gettext_comact = False\n",
    "gettext_uuid = True\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e9a7b04-444f-4456-a5d9-19806379636e",
   "metadata": {},
   "source": [
    "## 生成.pot翻译文档，在docs目录下\n",
    "\n",
    "执行以下代码：\n",
    "\n",
    "```\n",
    "sphinx-build -b gettext ./source build/gettext\n",
    "```\n",
    "\n",
    "生成zh_CN版本的翻译文件：\n",
    "\n",
    "```\n",
    "sphinx-intl update -p ./build/gettext -l zh_CN\n",
    "```\n",
    "\n",
    "软件在目录locales/zh_CN/LC_MESSAGES生成.po文档\n",
    "\n",
    "使用任一文本编辑器打开，内容如下\n",
    "\n",
    "```\n",
    "msgid \"Gunicorn - WSGI server\"\n",
    "msgstr \"\"\n",
    "```\n",
    "\n",
    "msgstr \"\"的引号内输入中文翻译内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32a43d24-26ab-430b-8b68-872d28bb5914",
   "metadata": {},
   "source": [
    "## 编译.pot到html\n",
    "\n",
    "```\n",
    "sphinx-build -b html -D language=zh_CN ./source/ build/html/zh_CN\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4ee7a81-2468-4848-8341-d91e8a2a9245",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
